package nc.ui.med.bd.medbreeddoc;

import java.util.Collection;

import nc.bs.framework.common.NCLocator;
import nc.bs.framework.exception.ComponentException;
import nc.bs.logging.Logger;
import nc.bs.uap.bd.BDRuntimeException;
import nc.itf.med.bd.medbreeddoc.IMedbreeddoc;
import nc.itf.uap.IUAPQueryBS;
import nc.vo.med.bd.medbreeddoc.MedbreeddocVO;
import nc.vo.med.medcatatype.MedCataTypeVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.BusinessRuntimeException;

public class Medbreeddoc_Client {

	private static IMedbreeddoc mbdService;
	private static IUAPQueryBS uapQueryService;

	private static IMedbreeddoc getMbdService() {
		if (mbdService == null) {
			try {
				mbdService = (IMedbreeddoc) NCLocator.getInstance().lookup(IMedbreeddoc.class.getName());
			} catch (ComponentException e) {
				Logger.error(e.getMessage(), e);
				throw new BDRuntimeException("cann't locate IMedbreeddoc");
			}
		}
		return mbdService;
	}
	
	public static IUAPQueryBS getUapQueryService() {
		if (uapQueryService == null) {
			try {
				uapQueryService = (IUAPQueryBS) NCLocator.getInstance().lookup(IUAPQueryBS.class.getName());
			} catch (ComponentException e) {
				Logger.error(e.getMessage(), e);
				throw new BDRuntimeException("cann't locate IMedbreeddoc");
			}
		}
		return uapQueryService;
	}

	public static void delete(MedbreeddocVO arg0) throws Exception {
		getMbdService().deleteMedbreeddocVO(arg0);
	}

	public static java.lang.String insert(MedbreeddocVO arg0) throws Exception {
		return getMbdService().insertMedbreeddocVO(arg0);
	}

	public static void update(MedbreeddocVO arg0) throws Exception {
		getMbdService().updateMedbreeddocVO(arg0);
	}

	public static MedbreeddocVO[] queryAll(java.lang.String arg0) throws Exception {
		return getMbdService().queryMedbreeddoc(arg0);
	}
	
	public static MedCataTypeVO[] queryCataTypeByCorpPk(String pk_corp){
		
		MedCataTypeVO[] cataTypeVOs = null;
		String where = "pk_corp='" + pk_corp + "' or pk_corp='0001' order by medcatatypecode";
		try {
			Collection c = getUapQueryService().retrieveByClause(MedCataTypeVO.class, where);
			if (c != null && c.size() > 0) {
				cataTypeVOs = (MedCataTypeVO[]) c.toArray(new MedCataTypeVO[c.size()]);
			}
		} catch (BusinessException e) {
			throw new BusinessRuntimeException(e.getMessage());
		}
		return cataTypeVOs;
	}
	
}
